package willevaluate.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.ArrayList;

import willevaluate.activity.WillCollegeDetail;
import willevaluate.bean.OrderCollegeBean;
import view.MyImageLoader;

/**
 * Created by Administrator on 2017/4/21.
 */

public class OrderCollegeAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<OrderCollegeBean.CollegeListBean> arrayList;
    private String type;//文理科
    private String count;

    public OrderCollegeAdapter(Context context, ArrayList<OrderCollegeBean.CollegeListBean> arrayList,String count, String type) {
        this.context = context;
        this.arrayList = arrayList;
        this.type = type;
        this.count = count;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;
        if(convertView == null){
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.ordercollege_item,null);
            myHolder.ordercollege_list_item_icon = (RoundedImageView) convertView.findViewById(R.id.ordercollege_list_item_icon);
            myHolder.ordercollege_list_item_school_name = (TextView) convertView.findViewById(R.id.ordercollege_list_item_school_name);
            myHolder.ordercollege_list_item_school_count = (TextView) convertView.findViewById(R.id.ordercollege_list_item_school_count);
            myHolder.ordercollege_list_item_school_rank = (TextView) convertView.findViewById(R.id.ordercollege_list_item_school_rank);
            myHolder.ordercollege_list_item_type = (TextView) convertView.findViewById(R.id.ordercollege_list_item_type);
            myHolder.ordercollege_list_item_more = (TextView) convertView.findViewById(R.id.ordercollege_list_item_more);
            myHolder.ordercollege_list_item_more_num = (TextView) convertView.findViewById(R.id.ordercollege_list_item_more_num);
            convertView.setTag(myHolder);
        }else{
            myHolder = (MyHolder) convertView.getTag();
        }
        if ("文科".equals(type)) {
            //文科
            myHolder.ordercollege_list_item_type.setText("16年文科最低分 : ");
        } else {
            //理科
            myHolder.ordercollege_list_item_type.setText("16年理科最低分 : ");
        }
        myHolder.ordercollege_list_item_school_name.setText(arrayList.get(position).getCollege());
        myHolder.ordercollege_list_item_school_count.setText(arrayList.get(position).getScore());
        myHolder.ordercollege_list_item_school_rank.setText(arrayList.get(position).getRank());
        if(arrayList.get(position).getGraduate()!=null){
            myHolder.ordercollege_list_item_more.setText("考研率 : ");
            myHolder.ordercollege_list_item_more_num.setText(arrayList.get(position).getGraduate());
        }
        if(arrayList.get(position).getEmployment()!=null){
            myHolder.ordercollege_list_item_more.setText("就业率 : ");
            myHolder.ordercollege_list_item_more_num.setText(arrayList.get(position).getEmployment());
        }
        if(arrayList.get(position).getSex()!=null){
            myHolder.ordercollege_list_item_more.setText("男女比例 : ");
            myHolder.ordercollege_list_item_more_num.setText(arrayList.get(position).getSex());
        }
        MyImageLoader.showImage(arrayList.get(position).getIcon(), myHolder.ordercollege_list_item_icon);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, WillCollegeDetail.class);
                i.putExtra("college",arrayList.get(position).getCollege());
                i.putExtra("type",type);
                i.putExtra("count",count);
                i.putExtra("probability",arrayList.get(position).getProbability());
                i.putExtra("rank",arrayList.get(position).getRank());
                context.startActivity(i);

            }
        });
        return convertView;
    }


    class MyHolder {
        RoundedImageView ordercollege_list_item_icon;//校徽
        TextView ordercollege_list_item_school_name;//学校名字
        TextView ordercollege_list_item_school_count;//分数
        TextView ordercollege_list_item_school_rank;//排名
        TextView ordercollege_list_item_type;//科目
        TextView ordercollege_list_item_more;//就业率，男女比例，考研率
        TextView ordercollege_list_item_more_num;//就业率，男女比例，考研率数字
    }
}
